<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>网站后台管理系统</title>
<link href="themes/css/login.css" rel="stylesheet" type="text/css" />
<script src="javascripts/speedup.js" type="text/javascript"></script>

<script src="javascripts/jquery-1.4.4.js" type="text/javascript"></script>
<script src="javascripts/jquery.cookie.js" type="text/javascript"></script>
<script>
	(function() {
		var username=$.cookie("username");
		if(username){
			$("input[name=username]").val(username);
			$("input[name=password]").focus();
		}else{
			$("input[name=username]").focus();
		}
	})(jQuery)
	
	function login(form){
		var $form=$(form);
		var username=$form.find("input[name=username]").val();
		if(!username){
			alert("用户名不能为空，请输入！");
			$form.find("input[name=username]").focus();
		}
		
		var pwd=$form.find("input[name=password]").val()
		if(!pwd){
			alert("密码不能为空，请输入！");
			$form.find("input[name=password]").focus();
		}
		
		var param={username:username,password:pwd};
		$.post("/services/account/login",param,function(data){
			if(data.message){
				var a=$("<a></a>");
				a.html(data.message);
				alert(a.text());
				$form.find("input[name=username]").focus();
			}else{
				var user=data.result;
				$.cookie("user_id",user.user_id);
				$.cookie("username",user.username,{expires:20});
				$.cookie("role",user.role.role);
				$.cookie("rolename",user.role.name);
				$.cookie("is_login",true);
				location.href="/management";
			}
		},"json");
		return false;
	}
</script>
</head>
<body>
	<div id="login">
		<div id="login_header">
			<!-- 	
			<h1 class="login_logo">
				<a href="#"><img src="themes/default/images/login_logo.gif" /></a>
			</h1>
			 -->
		</div>
		<div id="login_content">
			<div class="loginForm">
				<form action="index.html" onsubmit="return login(this);">
					<p>
						<label>用户名：</label> <input type="text" name="username" size="30" class="login_input" />
					</p>
					<p>
						<label>密码：</label> <input type="password" name="password" size="30" class="login_input" />
					</p>
					<div class="login_bar">
						<input class="sub" type="submit" value=" " />
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>